import User from '../models/user';
import componentContainer from '../../components/componentContainer';
import buildInRobots from '../common/buildinRobots';

componentContainer.init({});

function init() {
  const robotPromises = buildInRobots.map(robot =>
    User.findOneAndUpdate({ username: robot.name, isRobot: true }, robot, {
      new: true,
      upsert: true,
    }));

  return Promise.all(robotPromises);
}

if (!module.parent) {
  // run in script
  init()
    .then((result) => {
      console.log(result);
      process.exit();
    })
    .catch((e) => {
      console.log(e);
    });
}

export default init;
